function jump(h)
{
    var top = document.getElementById(h).offsetTop;
    window.scrollTo(0, top);
}

var ie = (function(){

    var undef,
        v = 3,
        div = document.createElement('div'),
        all = div.getElementsByTagName('i');

    while (
        div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
        all[0]
    );

    return v > 4 ? v : undef;

}());

$(document).ready(function(){

	/* back to top*/

    var offset = 250;
    var duration = 1000;
    $(window).scroll(function() {
        if ($(this).scrollTop() > offset) {
            $('.backToTop').fadeIn(duration);
        } else {
            $('.backToTop').fadeOut(duration);
        }
    });

    $('.backToTop').click(function(event) {
        event.preventDefault();
        $('html, body').animate({scrollTop: 0}, duration);
        return false;
    })

    //

	$('#page-loader').fadeOut(0);

	/*============================================
	Page Preloader
	==============================================*/

	$(window).load(function(){
		$('#page-loader').fadeOut(500);
	});

	/*============================================
	Navigation Functions
	==============================================*/
	// if ($(window).scrollTop()< 10){
	// 	$('#main-nav').removeClass('scrolled');
	// }
	// else{
	// 	$('#main-nav').addClass('scrolled');
	// }

	// $(window).scroll(function(){
	// 	if ($(window).scrollTop()< 10){
	// 		$('#main-nav').removeClass('scrolled');
	// 	}
	// 	else{
	// 		$('#main-nav').addClass('scrolled');
	// 	}
	// });

	$('a.scrollto').click(function(e){
		e.preventDefault();
		var target =$(this).attr('href');
		$('html, body').stop().animate({scrollTop: $(target).offset().top}, 1600, 'easeInOutExpo',
			function(){window.location.hash =target;});

		if ($('.navbar-collapse').hasClass('in')){
			$('.navbar-collapse').removeClass('in').addClass('collapse');
		}
	});

	/*============================================
	Tabs
	==============================================*/

	$('.toggle-tabs').click(function(e){
		e.preventDefault()

		if($(this).is('.active')){return;}
		$(this).tab('show');

		$(this).siblings('.toggle-tabs').removeClass('active');
		$(this).addClass('active');
	})

	$('.toggle-tabs').on('shown.bs.tab', function (e) {
	  $('.tab-content').addClass('fadeOut');

	  setTimeout(function(){
		$('.tab-content').removeClass('fadeOut');
	  },200)
	})

	var hidden_nav_lock = false

	$('#site-nav').on('activate.bs.scrollspy', function () {
		var currentItem = $("#site-nav li.active > a").attr("href")

		if (currentItem === "#rohto-contain") {
			$('#main-nav').css("top", "-100px")
			// $('.backToTop').show()

		}else{
			$('#main-nav').css("top", "0px")
			// $('.backToTop').hide()
		}

	});

	/*============================================
	Skills
	==============================================*/
	$('#skills').waypoint(function(){
		$('.chart').each(function(){
		$(this).easyPieChart({
				size:200,
				animate: 2000,
				lineCap:'butt',
				scaleColor: false,
				trackColor: 'transparent',
				barColor: $('.main-color').css('color'),
				lineWidth: 5,
				easing:'easeOutQuad'
			});
		});
	},{offset:'80%'});
	/*============================================
	Filter Projects
	==============================================*/

	$('.project-count').each(function(){

		var filter = $(this).parent('.btn').attr('data-filter');
		$(this).text($('.project-item'+filter).length);

	});

	$('#filter-works .btn').click(function(e){
		e.preventDefault();

		$('#filter-works .btn').removeClass('active');
		$(this).addClass('active');

		var category = $(this).attr('data-filter');

		$('.project-item').addClass('filtered');
		$('.project-item').each(function(){
			if($(this).is(category)){
				$(this).removeClass('filtered');
			}
		});

		$('#projects-container').addClass('anim-out');

		setTimeout(function(){
			$('.project-item').show();
			$('.project-item.filtered').hide();
			$('#projects-container').removeClass('anim-out');
		},450);

		scrollSpyRefresh();
		waypointsRefresh();
	});

	/*============================================
	Project Viewer
	==============================================*/

	$('#project-viewer').addClass('add-slider');

	$('.project-item').click(function(e){

		e.preventDefault();

		loadProject($(this));

		$('#project-viewer').modal({backdrop:false});

	})

	/*Prevent Navbar movement*/
	$('#project-viewer').on('show.bs.modal',function(){
		$('#main-nav').width($('#main-nav').width());

	});

	$('#project-viewer').on('hidden.bs.modal',function(){
		$('#main-nav').width('auto');
	});


	/*Projects navigation*/
	$('.project-nav .next-project').click(function(){
		var $newProject = $('.project-item.active').next('.project-item');
		$('#project-viewer .container').fadeOut(500,function(){loadProject($newProject);});
	});

	$('.project-nav .previous-project').click(function(){
		var $newProject = $('.project-item.active').prev('.project-item');
		$('#project-viewer .container').fadeOut(500,function(){loadProject($newProject);});
	});

	function loadProject($project){

		$('.project-item').removeClass('active');
		$project.addClass('active');

		var projectLink = $project.attr('href').replace(/[#?]/g, '');

		window.location.hash = '?'+projectLink;

		$('#project-viewer-content').load(projectLink,function(){
			$('#project-viewer .container').fadeIn(500);
			afterLoadFn();
		});

	}

	function afterLoadFn(){

		$('#project-viewer').scrollTop(0);

		/*Show-Hide Nav butttons*/
		if($('.project-item.active').index()==0){$('#project-viewer .previous-project').addClass('hidden');}
		else{$('#project-viewer .previous-project').removeClass('hidden');}

		if($('.project-item.active').index()== ($('.project-item').length -1)){$('#project-viewer .next-project').addClass('hidden');}
		else{$('#project-viewer .next-project').removeClass('hidden');}

		$('.project-slider').flexslider({
			animation:'slide',
			slideshowSpeed: 4000,
			useCSS: true,
			directionNav: false,
			pauseOnAction: false,
			pauseOnHover: true,
			smoothHeight: false
		});

		$('.video-container').fitVids();
	}

	/*Close project Modal*/

	$('#project-viewer').on('hidden.bs.modal',function(){
		$('#project-viewer-content').empty();
		$('#project-viewer .container').fadeOut();
	});

	$('#project-viewer').on('hide.bs.modal',function(){
		window.location.hash = 'portfolio';
	});

	/*Open project by url*/
	var reg = /^[#]+[?]/;

	if(reg.test(window.location.hash)){
		var $project = $('.project-item[href="'+window.location.hash+'"]');
		$project.trigger('click');
	}

	/*============================================
	Tweets
	==============================================*/
	$('#twitter-slider').flexslider({
		slideshowSpeed: 5000,
		useCSS: true,
		directionNav: false,
		pauseOnAction: false,
		pauseOnHover: true,
		smoothHeight: false
	});

	/*============================================
	Testimonials
	==============================================*/
	$('#knowledgeSchool #testimonials-slider').flexslider({
		slideshow: false,
		animationSpeed: 0,
		useCSS: true,
		directionNav: false,
		controlNav: false,
		pauseOnAction: false,
		pauseOnHover: true,
		smoothHeight: false,
		controlNav: true,
	});

	$('#knowledgeSchool .testimonial-controls .previous').click(function(){
		$('#knowledgeSchool #testimonials-slider').flexslider('previous');
	});

	$('#knowledgeSchool .testimonial-controls .next').click(function(){
		$('#knowledgeSchool #testimonials-slider').flexslider('next');
	});


	$('#knowledgeSchool-2 #testimonials-slider').flexslider({
		slideshow: false,
		animationSpeed: 0,
		useCSS: true,
		directionNav: false,
		controlNav: false,
		pauseOnAction: false,
		pauseOnHover: true,
		smoothHeight: false,
		controlNav: true,
	});

	$('#knowledgeSchool-2 .testimonial-controls .previous').click(function(){
		$('#knowledgeSchool-2 #testimonials-slider').flexslider('previous');
	});

	$('#knowledgeSchool-2 .testimonial-controls .next').click(function(){
		$('#knowledgeSchool-2 #testimonials-slider').flexslider('next');
	});

	/*============================================
	Resize Functions
	==============================================*/
	var thumbSize = $('.project-item').width();

	$(window).resize(function(){

		if($('#projects-container').length){
			setTimeout(function(){
				// $('#projects-container').masonry('reload');
			},100);
		}


	});

	/*============================================
	Placeholder Detection
	==============================================*/
	if (!Modernizr.input.placeholder) {
		$('#contact-form').addClass('no-placeholder');
	}

	/*============================================
	Tooltips
	==============================================*/
	$("[data-toggle='tooltip']").tooltip({container: 'body'});

	/*============================================
	Waypoints Animations
	==============================================*/
	$(window).load(function(){

		$('.scrollimation').waypoint(function(){
			$(this).addClass('in');
		},{offset:'95%'});

	});

	/*============================================
	Refresh scrollSpy function
	==============================================*/
	function scrollSpyRefresh(){
		setTimeout(function(){
			$('body').scrollspy('refresh');
		},1000);
	}

	/*============================================
	Refresh waypoints function
	==============================================*/
	function waypointsRefresh(){
		setTimeout(function(){
			$.waypoints('refresh');
		},1000);
	}

	// IE

	if (ie && ie < 10) {
		$(".window .prev, .window .next, .window .close, #site-nav li.logo>a").css({
			"background": "#000",
			"filter": "alpha(opacity=0)"
		})
	}

});

/*(function() {
    window._CiQ10785 = window._CiQ10785 || [];
    window._CiQ10785.push(['_cookieUseRootDomain', true]);
    var c = document.createElement('script');
    c.type = 'text/javascript';
    c.async = true;
    c.charset = 'utf-8';
    c.src = '//collect.cn.miaozhen.com/ca/10785';
    var h = document.getElementsByTagName('script')[0];
    h.parentNode.insertBefore(c, h);
})();*/

(function(a, e, f, g, b, c, d) {a.ClickiTrackerName = b;
 a[b] = a[b] || function() {(a[b].queue = a[b].queue || []).push(arguments)};
 a[b].start = +new Date; c = e.createElement(f); d = e.getElementsByTagName(f)[0];
 c.async = 1; c.src = g; d.parentNode.insertBefore(c, d)
 })(window, document, 'script', '//stm-cdn.cn.miaozhen.com/clicki.min.js?v='+Math.round(new Date().getTime()/1000/300), 'stm_clicki');
stm_clicki('create', 'dc-1965', 'auto');
stm_clicki('send', 'pageview');

